﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using System.Data.SqlClient;

using FundSms.DBUtility;

namespace SmsDataDemo
{
    class Program
    {
        //private static string ConnectString = "Data Source=SMS;User Id=sms;Password=sms;Integrated security=no;";
        private static string OracleSQL = "INSERT INTO TSMS_SEND_HUNDSUN(L_SERIALNO,C_MOBILENO,C_CONTENT,C_PROPERTY,C_FROM,C_SMSNAME,C_SMSID,C_DATE,C_R1,C_R2,C_R3,C_R4,C_R5) values  (SEQ_SEND.Nextval,'{0}','{2}','0','111','test','{1}',Sysdate,'','','','','')";

        private static string SQL = "INSERT INTO TSMS_SEND_HUNDSUN(C_MOBILENO,C_CONTENT,C_PROPERTY,C_FROM,C_SMSNAME,C_SMSID,C_DATE,C_R1,C_R2,C_R3,C_R4,C_R5) values  ('{0}','{2}','0','111','test','{1}',GETDATE(),'','','','','')";

        private static string[] MobilePrefix = new string[] { "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "153", "156", "158", "159", "0571"};

        private static string DataType = System.Configuration.ConfigurationManager.AppSettings["DataType"];
        private static int DataCount = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["DataCount"]);
        private static string Content = "18日净值，增利1.3828/2.618；金利1.2728/3.4133;银利1.1027/3.0277;利息1.9950%";

        static void Main(string[] args)
        {
            if (DataType.ToUpper() == "ORACLE")
            {
                CreateOracleRecord(DataCount);
            }
            else
            {
                CreateSqlRecord(DataCount);
            }

            Console.ReadLine();
        }

        private static void CreateOracleRecord(int rownum)
        {
            string mobile = string.Empty;
            string content = string.Empty;

            for (int i = 0; i < rownum; i++)
            {
                mobile = GetRandomMobile();
                content = GetRandomContent();

                try
                {
                    OracleHelper.ExecuteNonQuery(OracleHelper.ConnectionStringClientSms, CommandType.Text, string.Format(OracleSQL, mobile, i + 1, content), (OracleParameter[])null);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message + "\r\n" + e.StackTrace);
                }

                Console.WriteLine(GetDateTime() + "第" + i + "条Oracle记录，" + mobile);
            }

            content = GetRandomContent();

            OracleHelper.ExecuteNonQuery(OracleHelper.ConnectionStringClientSms, CommandType.Text, string.Format(OracleSQL, "13989857156", rownum + 1, content), (OracleParameter[])null);
            OracleHelper.ExecuteNonQuery(OracleHelper.ConnectionStringClientSms, CommandType.Text, string.Format(OracleSQL, "13205719039", rownum + 2, content), (OracleParameter[])null);

        }

        private static void CreateSqlRecord(int rownum)
        {
            string mobile = string.Empty;
            string content = string.Empty;

            for (int i = 0; i < rownum; i++)
            {
                mobile = GetRandomMobile();
                content = GetRandomContent();

                try
                {
                    SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringClientSms, CommandType.Text, string.Format(SQL, mobile, i + 1, content), (SqlParameter[])null);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message + "\r\n" + e.StackTrace);
                }

                Console.WriteLine(GetDateTime() + "第" + i + "条Sql记录，" + mobile);
            }

            content = GetRandomContent();

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringClientSms, CommandType.Text, string.Format(SQL, "13989857156", rownum + 1, content), (SqlParameter[])null);
            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringClientSms, CommandType.Text, string.Format(SQL, "13205719039", rownum + 2, content), (SqlParameter[])null);

        }

        private static string GetRandomMobile()
        {
            int a = new Random(Guid.NewGuid().GetHashCode()).Next(0, 15);
            int b = new Random(Guid.NewGuid().GetHashCode()).Next(10000000, 99999999);

            return MobilePrefix[a] + b.ToString();
            
        }

        private static string GetRandomContent()
        {
            int a = new Random(Guid.NewGuid().GetHashCode()).Next(1, 11);

            if (a == 1)
            {
                return Content + "共产党";
            }
            else
            {
                return Content;
            }

        }

        private static string GetDateTime()
        {
            return "[" + DateTime.Now.ToString("HH:mm:ss") + "] ";
        }
    }
}
